package com.payService.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.payService.entity.TOrder;
import com.payService.mapper.TOrderMapper;
import com.payService.service.ITOrderService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author Mr.Tang
 * @since 2022-05-31
 */
@Service
public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> implements ITOrderService {



    /**
     *
     * 获取当天的售课情况
     *
     * */
    @Override
    public Map<String, Integer> getBuyCountToday(String date) {

        ArrayList<String> buyCount = baseMapper.getBuyCount(date);

        Map<String,Integer> map = new HashMap<>();
        int symbol  = 0;
        map.put("total",buyCount.size());
        for (int i = 1 ; i<buyCount.size();i++){
            if (buyCount.get(i).equals(buyCount.get(i-1))){
                symbol++;
                System.out.println(symbol);
                if(i == buyCount.size()-1){
                    map.put(buyCount.get(i),symbol+1);
                }
            } else {
                map.put(buyCount.get(i),symbol+1);
                symbol = 0;
            }
        }
        return map;
    }
}
